package com.wqiuqiu.gulimall.coupon.service.impl;

import com.fasterxml.jackson.databind.util.BeanUtil;
import com.wqiuqiu.common.to.SkuLadderTo;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wqiuqiu.common.PageUtils;
import com.wqiuqiu.common.Query;

import com.wqiuqiu.gulimall.coupon.dao.SkuLadderDao;
import com.wqiuqiu.gulimall.coupon.entity.SkuLadderEntity;
import com.wqiuqiu.gulimall.coupon.service.SkuLadderService;


@Service("skuLadderService")
public class SkuLadderServiceImpl extends ServiceImpl<SkuLadderDao, SkuLadderEntity> implements SkuLadderService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<SkuLadderEntity> page = this.page(
                new Query<SkuLadderEntity>().getPage(params),
                new QueryWrapper<SkuLadderEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public void saveLadderBatch(List<SkuLadderTo> skuLadderTos) {
        List<SkuLadderEntity> skuLadderEntities = skuLadderTos.stream().map(obj -> {
            SkuLadderEntity skuLadderEntity = new SkuLadderEntity();
            BeanUtils.copyProperties(obj, skuLadderEntity);
            return skuLadderEntity;
        }).collect(Collectors.toList());
        this.saveBatch(skuLadderEntities);
    }

}